#include <iostream>
using namespace std; 
#include <string> 
#include <list>
#include <vector>


void  process(vector<char> lc , list<string>& ans , string path1)
{
  if (lc.size() == 0)
  {
    ans.push_back(path1);
    return;
  }
  else 
  {
    for (int i = 0; i < lc.size(); i++)
    {
      char cur = lc[i];
      lc.erase(lc.begin() + i);
      process(lc , ans , path1 + cur);
      lc.insert(lc.begin() + i , cur);
    }
  }
}



int main()
{
  list<string> ans;
  vector<char> lc = {'a' , 'b' , 'c'};
  process(lc , ans , "");
  for (auto x : ans)
  {
    cout << x << " ";
  }
  cout << endl;
  return 0;
}
